<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<%
	
	mode = Request("mode")
	If mode = "checkLogin" Then 
		uid =  Replace(Request("uid"),"&","")
		uid =  Replace(Request("uid"),"-","")
		passwd = Replace(Request("passwd"),"&","")
		destFolder = Replace(Request("destFolder"),"&","") 

		If destFolder <> "" Then 
			destFolder = "/" & destFolder & "/"
		End If 
		
		authLogin = aFieldValue("SELECT ISNULL(COUNT(*),0) FROM tblUser WHERE userId='" & uid & "' AND passwd='" & passwd & "' AND delYN='N'")
		If authLogin = 1 Then 
			SQL = "SELECT *, CONVERT(varchar(16), loginOffDt, 121) loginOff FROM tblUser WHERE userId='" & uid & "'"	
			Set tchrRs=Server.CreateObject("ADODB.RecordSet")
			tchrRs.open SQL, DbCon

			If tchrRs.eof Or tchrRs.bof Then 
				Response.write "here"
			Else 
				isAblePerm = aFieldValue("SELECT ISNULL(COUNT(*),0) FROM tblUser WHERE userId='" & uid & "' AND loginOffDt > getdate()")
				If isAblePerm > 0 Then 
					if tchrRs("uLevel") = "09" then 
						Response.write "<META http-equiv='Content-Type' content='text/html; charset=utf-8'>"
						Response.write "<meta http-equiv='Cache-Control' content='no-cache'>"
						Response.write "<meta http-equiv='Pragma' content='no-cache'>"
						Response.write "<script> alert(""로그인 제한된 회원입니다.""); history.go(-1);</script>"
						Response.End
					else 
						dbCon.execute "INSERT INTO tblLoginLog(userId, IP, posit) VALUES('" & tchrRs("userId") & "','" & Request.ServerVariables("REMOTE_ADDR") & "','" & destFolder & "')"
						session("S_uid") = tchrRs("userId")
						session("S_part") = tchrRs("uPart")
						session("S_userNm") = tchrRs("userNm")
						session("S_level") = tchrRs("uLevel")
						session("S_perm") = tchrRs("uPerm")
						session("S_compCd") = tchrRs("compCd")
						session("S_destFolder") = destFolder
						Response.Cookies("S_uid") = tchrRs("userId")
						Response.Cookies("S_part") = tchrRs("uPart")
						Response.Cookies("S_userNm") = tchrRs("userNm")
						Response.Cookies("S_level") = tchrRs("uLevel")
						Response.Cookies("S_perm") = tchrRs("uPerm")
						Response.Cookies("S_compCd") = tchrRs("compCd")
						Response.Cookies("S_destFolder") = destFolder
	
						If Instr(tchrRs("uPerm"),"/10/") > 0 And destFolder = "" Then 
							dest = "dashBoard.asp"
						ElseIf Instr(tchrRs("uPerm"),"/11/") > 0 And destFolder = "" Then 
							dest = "board.asp"
						ElseIf Instr(tchrRs("uPerm"),"/12/") > 0 And destFolder = "" Then 
							dest = "graph.asp"
						ElseIf Instr(tchrRs("uPerm"),"/20/") > 0 Then 
							dest = "jobOrder.asp"
						ElseIf Instr(tchrRs("uPerm"),"/30/") > 0And destFolder = ""  Then 
							dest = "unitProcess.asp"
						ElseIf Instr(tchrRs("uPerm"),"/40/") > 0 Then 
							dest = "product.asp"
						ElseIf Instr(tchrRs("uPerm"),"/50/") > 0 Then 
							dest = "src.asp"
						ElseIf Instr(tchrRs("uPerm"),"/51/") > 0 Then 
							dest = "srcStore.asp"
						ElseIf Instr(tchrRs("uPerm"),"/52/") > 0 Then 
							dest = "equipBreak.asp"
						ElseIf Instr(tchrRs("uPerm"),"/60/") > 0 Then 
							dest = "order.asp"
						ElseIf Instr(tchrRs("uPerm"),"/61/") > 0 Then 
							dest = "company.asp"
						ElseIf Instr(tchrRs("uPerm"),"/62/") > 0 Then 
							dest = "estimate.asp"
						ElseIf Instr(tchrRs("uPerm"),"/70/") > 0 Then 
							dest = "comCode.asp"
						ElseIf Instr(tchrRs("uPerm"),"/71/") > 0 Then 
							dest = "member.asp"
						End If 
						Response.redirect destFolder & dest
					end if 
				Else
					Response.write "<META http-equiv='Content-Type' content='text/html; charset=utf-8'>"
					Response.write "<meta http-equiv='Cache-Control' content='no-cache'>"
					Response.write "<meta http-equiv='Pragma' content='no-cache'>"
					Response.write "<script> alert(""로그인 정보가 만료 되었습니다.""); history.go(-1);</script>"
					Response.End
				End If 
			End If 
		Else 
			Response.write "<META http-equiv='Content-Type' content='text/html; charset=utf-8'>"
			Response.write "<meta http-equiv='Cache-Control' content='no-cache'>"
			Response.write "<meta http-equiv='Pragma' content='no-cache'>"
			Response.write "<script> alert(""로그인 정보가 일치하지 않습니다""); history.go(-1);</script>"
			Response.End
		End If 
	Else 
			session("S_uid") = ""
			session("S_part") = ""
			session("S_userNm") = ""
			session("S_level") = ""
			session("S_compCd") = ""
			Response.Cookies("S_uid") = ""
			Response.Cookies("S_part") = ""
			Response.Cookies("S_userNm") = ""
			Response.Cookies("S_level") = ""
			Response.Cookies("S_compCd") = ""
			Response.redirect "./index.asp"
	End If 
%>